package main

import (
	"fmt"
	"os"
	"os/exec"
	"time"
)

func runCommand(command string, args ...string) error {
	cmd := exec.Command(command, args...)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	return cmd.Run()
}

func main() {
	// 打印当前时间
	fmt.Println("Starting the process at:", time.Now().Format("2006-01-02 15:04:05"))

	// 先运行 swag init 命令
	fmt.Println("Running swag init...")
	if err := runCommand("swag", "init", "-g", "./cmd/app/main.go", "-o", "api", "--parseDependency", "--parseInternal"); err != nil {
		fmt.Printf("Error running swag init: %v\n", err)
		return
	}

	// 再运行 main.go
	fmt.Println("Running main.go...")
	if err := runCommand("go", "run", "./cmd/app/main.go"); err != nil {
		fmt.Printf("Error running main.go: %v\n", err)
		return
	}

	// 打印结束时间
	fmt.Println("Process completed at:", time.Now().Format("2006-01-02 15:04:05"))
}
